# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=aiohttp
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=3.7.3
_gitcommit=2f655a59d0daedfa2a794996c4355b576c98ecc8
pkgrel=1
pkgdesc='HTTP client/server for asyncio (mingw-w64)'
arch=('any')
url="https://aiohttp.readthedocs.io/"
license=('Apache')
depends=("${MINGW_PACKAGE_PREFIX}-python-async-timeout"
"${MINGW_PACKAGE_PREFIX}-python-attrs"
"${MINGW_PACKAGE_PREFIX}-python-chardet"
"${MINGW_PACKAGE_PREFIX}-python-yarl")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools" "${MINGW_PACKAGE_PREFIX}-cython" "git")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-freezegun"
"${MINGW_PACKAGE_PREFIX}-python-pytest-runner"
"${MINGW_PACKAGE_PREFIX}-python-pytest-cov"
"${MINGW_PACKAGE_PREFIX}-python-pytest-forked"
"${MINGW_PACKAGE_PREFIX}-python-pytest-mock"
"${MINGW_PACKAGE_PREFIX}-python-pytest-timeout"
"${MINGW_PACKAGE_PREFIX}-python-pytest-xdist"
"${MINGW_PACKAGE_PREFIX}-python-trustme")
source=("git+https://github.com/aio-libs/aiohttp#commit=${_gitcommit}"
        "git+https://github.com/nodejs/http-parser")
sha256sums=('SKIP'
            'SKIP')

pkgver() {
  cd $srcdir/${_realname}
  git describe --tags | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {  
  cd "$srcdir/${_realname}"
  git submodule init
  git config submodule."vendor/http-parser".url "${srcdir}/http-parser"
  git submodule update --recursive
  cd ..
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}" "python-build-${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  sed 's|.install-cython ||' -i Makefile
}

build() {
  msg "Python build for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  make cythonize
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py test || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.txt"
}
